<?
require '../../../wp-load.php';

$menu_id = $_POST['menu-id'];

$image_name = "menu_image_".$menu_id;
$file_path = trailingslashit(WP_PLUGIN_DIR) . dirname(plugin_basename(__FILE__))."/files/";

//평상시 이미지 업로드한다.
if($_FILES['menu-image1']['error'] == 0 && $_FILES['menu-image1']['name']) {
    
    // 기존 이미지 삭제
    $menu_image1_src = get_post_meta($menu_id, "_menu_image1_src");    
    if( isset($menu_image1_src[0]) && $menu_image1_src[0] ){
        @unlink( $file_path.$menu_image1_src[0] );        
    }
    
    $ext1 = strtolower(substr(strrchr($_FILES['menu-image1']['name'],"."),1));    
    $image1_fullname = $image_name.".".$ext1;
    
    @move_uploaded_file( $_FILES['menu-image1']['tmp_name'], $file_path.$image1_fullname ); 
    update_post_meta($menu_id, "_menu_image1_src", $image1_fullname);    
}

//마우스오버 이미지 업로드한다.
if($_FILES['menu-image2']['error'] == 0 && $_FILES['menu-image2']['name']) {
    
    // 기존 이미지 삭제
    $menu_image2_src = get_post_meta($menu_id, "_menu_image2_src");    
    if( isset($menu_images_src[0]) && $menu_image2_src[0] ){
        @unlink( $file_path.$menu_image2_src[0] );        
    }
    
    $ext2 = strtolower(substr(strrchr($_FILES['menu-image2']['name'],"."),1));    
    $image2_fullname = $image_name."_ov.".$ext2;
    
    @move_uploaded_file( $_FILES['menu-image2']['tmp_name'], $file_path.$image2_fullname ); 
    update_post_meta($menu_id, "_menu_image2_src", $image2_fullname);
}

update_post_meta($menu_id, "_menu_type", $_POST['menu-type']);
?>
<script type="text/javascript"> 
    location.href='./<?php echo "./seoul-menu-iframe.php?id=".$menu_id;?>';
</script>
